package cn.tedu.clyback.department.controller;


import cn.tedu.clyback.base.response.JsonResult;
import cn.tedu.clyback.department.pojo.dto.DepartmentSaveParam;
import cn.tedu.clyback.department.pojo.dto.DepartmentSelectParam;
import cn.tedu.clyback.department.pojo.vo.DepartmentVO;
import cn.tedu.clyback.department.service.DepartmentService;
import cn.tedu.clyback.menu.pojo.dto.MenuSaveParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/department")
public class DepartmentController {
    @Autowired
    DepartmentService departmentService;

    @GetMapping("/select")
    public JsonResult selectDepartment(DepartmentSelectParam departmentSelectParam){
      log.debug("开始处理【查询部门】的请求，参数：{}", departmentSelectParam);
        List<DepartmentVO> list = departmentService.selectDepartment(departmentSelectParam);
        return JsonResult.ok(list);
    }

    @PostMapping("/update/status/{departmentId}/{status}")
    public JsonResult updateStatus(@PathVariable Integer departmentId,@PathVariable String status){
        log.debug("开始处理【更新部门状态】的请求，参数：{}", departmentId,status);
        departmentService.updateStatus(departmentId,status);
        return JsonResult.ok();
    }

    @PostMapping("/save")
    public JsonResult saveRole(DepartmentSaveParam departmentSaveParam){
        log.debug("开始处理【保存部门】的请求，参数：{}", departmentSaveParam);
        departmentService.saveDepartment(departmentSaveParam);
        return JsonResult.ok();
    }


    @PostMapping("/delete/{departmentId}")
    public JsonResult deleteRole(@PathVariable Integer departmentId){
        log.debug("开始处理【删除部门】的请求，参数：{}", departmentId);
        departmentService.deleteDepartment(departmentId);
        return JsonResult.ok();
    }
}